package com.yuan.model_convenient.rest;


import com.yuan.model_common.dto.CommonQueryCriteria;
import com.yuan.model_convenient.domain.ConvenientReporting;
import com.yuan.model_convenient.service.ConvenientReportingService;
import com.yuan.model_convenient.service.dto.ConvenientReportingDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Api(tags = "物业便民: 小区报备管理")
@RestController
@RequestMapping("/api/convenientReporting")
@RequiredArgsConstructor
public class ConvenientReportingController {

    private final ConvenientReportingService convenientReportingService;

    @ApiOperation("导出/convenient/reporting")
    @GetMapping(value = "/download")
    public void exportReporting(HttpServletResponse response, CommonQueryCriteria criteria) throws IOException {
//        convenientReportingService.download(convenientReportingService.queryAll(criteria), response);
    }

    @GetMapping("/findList")
    @Log("查询/api/convenient/reporting")
    @ApiOperation("查询/api/convenient/reporting")
    public ResponseEntity<PageResult<ConvenientReportingDto>> queryReportingList(CommonQueryCriteria criteria, Pageable pageable) {
//        Pageable pageable = PageRequest.of(page, size);
        PageResult<ConvenientReportingDto> ConvenientReportingDtoPageResult = convenientReportingService.queryAll(criteria, pageable);
        return new ResponseEntity<>(ConvenientReportingDtoPageResult, HttpStatus.OK);
    }


    @Log("新增/api/convenient/reporting")
    @ApiOperation("新增/api/convenient/reporting")
    @PostMapping("/create")
    public ResponseEntity<Object> createReporting(@Validated @RequestBody ConvenientReporting resources) {
        convenientReportingService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("修改/api/convenient/reporting")
    @ApiOperation("修改/api/convenient/reporting")
    @PostMapping("/update")
    public ResponseEntity<Object> updateReporting(@Validated @RequestBody ConvenientReporting resources) throws Exception {
        convenientReportingService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除/api/convenient/reporting")
    @ApiOperation("删除/api/convenient/reporting")
    @PostMapping("/delete")
    public ResponseEntity<Object> deleteReporting(@RequestParam Integer ids) {
        convenientReportingService.delete(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
